D:\a\tools.proto\tools.proto\compiler\src\api\tools\rust.rs
Line | Count | Source |
1 | | // Copyright (c) 2024, BlockProject 3D |
2 | | // |
3 | | // All rights reserved. |
4 | | // |
5 | | // Redistribution and use in source and binary forms, with or without modification, |
6 | | // are permitted provided that the following conditions are met: |
7 | | // |
8 | | // * Redistributions of source code must retain the above copyright notice, |
9 | | // this list of conditions and the following disclaimer. |
10 | | // * Redistributions in binary form must reproduce the above copyright notice, |
11 | | // this list of conditions and the following disclaimer in the documentation |
12 | | // and/or other materials provided with the distribution. |
13 | | // * Neither the name of BlockProject 3D nor the names of its contributors |
14 | | // may be used to endorse or promote products derived from this software |
15 | | // without specific prior written permission. |
16 | | // |
17 | | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
18 | | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
19 | | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
20 | | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
21 | | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
22 | | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
23 | | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
24 | | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
25 | | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
26 | | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
27 | | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | | |
29 | | use crate::api::config; |
30 | | use crate::api::config::model; |
31 | | use crate::api::config::model::Config; |
32 | | use crate::api::core::generator::{Context, Generator}; |
33 | | use crate::api::tools::Error; |
34 | | use crate::api::tools::GenTools; |
35 | | use crate::gen::{GeneratorRust, RustImportSolver, RustParams}; |
36 | | |
37 | | pub struct Rust; |
38 | | |
39 | | impl GenTools for Rust { |
40 | | type Params<'a> = model::RustParams<'a>; |
41 | | type Generator = GeneratorRust; |
42 | | type Solver = RustImportSolver; |
43 | | |
44 | 2 | fn new_solver() -> Self::Solver { |
45 | 2 | RustImportSolver |
46 | 2 | } |
47 | | |
48 | 2 | fn new_generator() -> Self::Generator { |
49 | 2 | GeneratorRust |
50 | 2 | } |
51 | | |
52 | 2 | fn generate<'b>( |
53 | 2 | generator: &'b Generator<'_, Self::Generator>, |
54 | 2 | context: &mut Context<'b, Self::Solver>, |
55 | 2 | config: &Config<Self::Params<'_>>, |
56 | 2 | ) -> Result<(), Error> { |
57 | 2 | config::core::generate( |
58 | 2 | generator, |
59 | 2 | context, |
60 | 2 | config, |
61 | 10 | |v| { |
62 | 10 | if v.disable_write.is_none() Branch (62:20): [True: 10, False: 0]
Branch (62:20): [Folded - Ignored]
|
63 | 10 | && v.disable_read.is_none() Branch (63:24): [True: 10, False: 0]
Branch (63:24): [Folded - Ignored]
|
64 | 10 | && v.write_async.is_none() Branch (64:24): [True: 7, False: 3]
Branch (64:24): [Folded - Ignored]
|
65 | 7 | && v.union_set_discriminant.is_none() Branch (65:24): [True: 6, False: 1]
Branch (65:24): [Folded - Ignored]
|
66 | 6 | && v.list_wrappers.is_none() Branch (66:24): [True: 3, False: 3]
Branch (66:24): [Folded - Ignored]
|
67 | 3 | && v.struct_to_mut.is_none() Branch (67:24): [True: 3, False: 0]
Branch (67:24): [Folded - Ignored]
|
68 | 3 | && v.struct_dupe.is_none() Branch (68:24): [True: 2, False: 1]
Branch (68:24): [Folded - Ignored]
|
69 | 2 | && v.message_offsets.is_none() Branch (69:24): [True: 1, False: 1]
Branch (69:24): [Folded - Ignored]
|
70 | | { |
71 | 1 | return None; |
72 | 9 | } |
73 | 9 | let mut params = RustParams::default(); |
74 | 9 | if let Some(v0 ) = &v.disable_read { Branch (74:24): [True: 0, False: 9]
Branch (74:24): [Folded - Ignored]
|
75 | 0 | for v in v { |
76 | 0 | params = params.disable_read(v); |
77 | 0 | } |
78 | 9 | } |
79 | 9 | if let Some(v0 ) = &v.disable_write { Branch (79:24): [True: 0, False: 9]
Branch (79:24): [Folded - Ignored]
|
80 | 0 | for v in v { |
81 | 0 | params = params.disable_write(v); |
82 | 0 | } |
83 | 9 | } |
84 | 9 | if let Some(v1 ) = &v.struct_dupe { Branch (84:24): [True: 1, False: 8]
Branch (84:24): [Folded - Ignored]
|
85 | 2 | for v1 in v { |
86 | 1 | params = params.enable_struct_dupe(v); |
87 | 1 | } |
88 | 8 | } |
89 | 9 | params = params.enable_write_async(v.write_async.unwrap_or_default()); |
90 | 9 | params = params.enable_union_set_discriminant(v.union_set_discriminant.unwrap_or_default()); |
91 | 9 | params = params.enable_list_wrappers(v.list_wrappers.unwrap_or_default()); |
92 | 9 | params = params.enable_struct_to_mut(v.struct_to_mut.unwrap_or_default()); |
93 | 9 | params = params.enable_message_offsets(v.message_offsets.unwrap_or_default()); |
94 | 9 | Some(params) |
95 | 10 | }, |
96 | 2 | &RustParams::default(), |
97 | 2 | )?0 ; |
98 | 2 | Ok(()) |
99 | 2 | } |
100 | | } |